#include "wrapper_quasi.h"

/** Wrapper for Numerical recipies dfpmin function (QN) 
 *
 * @param pI InOut parameter. As input: starting point for minimization and as output: final point of mimimization 
 * @param gtol Input parameter specifies convergence criterion on when gradient close enough to zero
 * @param fret Output value of final minimization function value
 * @param Funcdd Function to minimize
 *  
 */
void WrapperQuasi(double *pI, double gtol, double &fret, Funcdd &funcd, string& directory)
{
  VecDoub p(funcd.NInput);
  for(int i = 1; i<=funcd.NInput; i++)
  {
    p[i-1] = pI[i];
  }
  int iter;

  try
  {
    dfpmin(p, gtol, iter, fret, funcd, directory);
  }
  catch(...)
  {
    std::cout << "Inside generic catch statement" << endl;
    for(int i = 1; i<=funcd.NInput; i++)
    {
      pI[i] = p[i-1];
    }
    return;
  }
  for(int i = 1; i<=funcd.NInput; i++)
  {
    pI[i] = p[i-1];
  }
}
